#ifndef HMM_H
#define HMM_H

#include "mlgesture_global.h"

#include <string>
#include <vector>

#include <QXmlStreamReader>
#include <QXmlStreamWriter>

#include "handgestureexception.h"

using namespace std;

namespace mlgesture {

class MLGESTURESHARED_EXPORT Hmm
{
public:
	enum ModelConnection {
		LINEAR_MODEL = 1,
		FULL_CONNECTED_MODEL = 2
	};
	Hmm();
	Hmm(int states, int observation, ModelConnection mode = LINEAR_MODEL);
	~Hmm();
	void setParams(int states, int observation, ModelConnection mode = LINEAR_MODEL) throw(HandGestureException);

	double viterbi(const vector<int>& data) const;
	void baumWelsh(const vector<vector<int> >& data) throw(HandGestureException);
	bool read(QString file) throw(HandGestureException);
	void write(QString file) throw(HandGestureException);

	static Hmm* makeGarbage(const vector<Hmm*> models) throw(HandGestureException);
	int getStatesNum() const;

private:
	int statesCount_;
	int observationCount_;
	vector<vector<double> > observation_;
	vector<vector<double> > transition_;
	vector<double> pi_;

	QXmlStreamReader xmlReader_;
	QXmlStreamWriter xmlWriter_;
};

}

#endif // HMM_H
